package sjtu.ist.warehouse4ws.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import sjtu.ist.warehouse4ws.model.Functionpoint;
import sjtu.ist.warehouse4ws.service.FunctionpointService;
import sjtu.ist.warehouse4ws.service.OplogService;

import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ShowProcessAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7797460115963418903L;
	private List<Functionpoint> functionList = new ArrayList<Functionpoint>();
	private FunctionpointService functionpointService;
	private OplogService oplogService;
	private String processid;

	public String getProcessid() {
		return processid;
	}

	public void setProcessid(String processid) {
		this.processid = processid;
	}

	public void setFunctionpointService(
			FunctionpointService functionpointService) {
		this.functionpointService = functionpointService;
	}
	
	public void setOplogService(OplogService oplogService) {
		this.oplogService = oplogService;
	}


	public String showFunction() {

		HttpServletRequest request = ServletActionContext.getRequest();
		this.processid = request.getParameter("cid");
		this.functionList = functionpointService
				.getFunctionpointList(processid);

		//插入日志记录/////////////////////////////////////////////////////
		ActionContext actionContext = ActionContext.getContext();
		Map session = actionContext.getSession();
		String user_id = session.get("user_id").toString();
		String file="";
		if(functionList!=null && functionList.size() > 0){
			file=functionList.get(0).getFileId();
		}
		oplogService.recordLog(user_id, file, "查看流程模型", "readop");
		//////////////////////////////////////////////////////////////////////
		
		return SUCCESS; // 获取得到的数据

	}

	@JSON(name = "totalFunction")
	public int getTotalAttribute() {
		return this.functionList.size();
	}

	@JSON(name = "function")
	public List<Functionpoint> getFunctionList() {
		return this.functionList;
	}
}
